local _, ZLAUTO = ...

--多个相同物品，通过获取先后顺序从1开始做标记，所以整个框架标识通过itemlink+标记区分
--LOOT_OPENED事件监控掉落物品清单，全部循环查找auctionFrames里是否存在掉落物品的itemlink，如果存在，循环结束后判断存在几个，记录itemlink物品的标记，然后添加新的待拍卖框架里，
--[=[]
    ItemAuctionFrame.state = "waiting" --waiting,auctioning,success,failed，会变
    ItemAuctionFrame.lgnore = false --是否忽略，玩家自己控制
    ItemAuctionFrame.itemlink = itemlink  --不会变
    ItemAuctionFrame.itemindex = 1 --标记，用去区分多个相同物品，不会变
    ItemAuctionFrame.startbidamount = 500 --起拍价
    ItemAuctionFrame.curbidamount = 600 --当前出价
    ItemAuctionFrame.bidIncrement = 100 --每次最低加价，不会变
    ItemAuctionFrame.curbidder = nil --当前出价者，会变

    需监听的话：
    --ML发送的：
    开始拍卖："开始拍卖[%d]%s，请在团队聊天中出价，起步价：%dg，每次最低加价：%dg"
    取消拍卖：
    暂停拍卖："[%d]%s已暂停拍卖！"
    继续拍卖：
    撤销最高价：
    拍卖结束：
    全部开始：--没必要，已取消
    全部停止：--没必要，已取消
    全部暂停：
    全部继续：
    --全员(包刮ML)发送的
    出价
]=]
local ZL = ZLAUTO.mainFrame
local PlayerIsML = ZL.PlayerIsML
ZL.addonVersion = "1.0.4"
ZL.MLname = nil

ZL.options = {
	type = "group",
	args = {
		show = {
			type = "toggle",
			name = "显示",
			desc = "显示插件界面",
			get = function() return not ZL.opt.hide end,
			set = function(info, value)
				ZL.opt.hide = not value
				if value then
                    ZL:Show()
                else
                    ZL:Hide()
                end
			end,
			order = 1,
			width = "half",
		},
		behaviour = {
			type = "group",
			name = "行为选项",
			args = {
				startBid = {
					type = "range",
					name = "起拍价",
					min = 50,
					max = 100000,
					softMax = 100000,
					softMin = 50,
					step = 50,
					get = function() return ZL.opt.startBid end,
					set = function(info, value) ZL.opt.startBid = value end,
					order = 1,
                    width = "double",
				},
				minIncrement = {
					type = "range",
					name = "最低加价",
					min = 50,
					max = 100000,
					softMax = 100000,
					softMin = 50,
					step = 50,
					get = function() return ZL.opt.increment end,
					set = function(info, value) ZL.opt.increment = value end,
					order = 2,
                    width = "double",
				},
				customSettings = {
					type = "execute",
					name = "物品设置",
					func = function()
						ZL.ItemSettingFrame:Show()
						LibStub("AceConfigDialog-3.0"):Close("金团自动拍卖助手")
					end,
					order = 2.5,
				},
				-- AdditionalRaidMembers = {
				-- 	dialogInline = true,
				-- 	name = "额外的团队成员",
				-- 	order = 5,
				-- 	type = "group",
				-- 	args = {
				-- 		isEnabled = {
				-- 			order = 1,
				-- 			type = "toggle",
				-- 			name = "启用",
				-- 			set = function(info, value) ZL.opt.AdditionalRaidMembersEnable = value end,
				-- 			get = function() return ZL.opt.AdditionalRaidMembersEnable end,
				-- 		},
				-- 		shareAmount = {
				-- 			order = 2,
				-- 			type = "range",
				-- 			name = "人数",
				-- 			min = 0,
				-- 			max = 40,
				-- 			step = 1,
				-- 			isPercent = false,
				-- 			set = function(info, value) ZL.opt.AdditonalRaidMembersAmount = value end,
				-- 			get = function() return ZL.opt.AdditonalRaidMembersAmount end,
				-- 		},
				-- 	},
				-- },
				minQuality = {
					type = "select",
					values = function()
						local vtab = {}
						for key, tab in pairs(ITEM_QUALITY_COLORS) do
							if _G["ITEM_QUALITY" .. key .. "_DESC"] then
								vtab[key] = tab.hex .. _G["ITEM_QUALITY" .. key .. "_DESC"] .. "|r"
							end
						end
						vtab[-1] = "|cffaa2222" .. "使用系统的拾取分配阈值设置" .. "|r"
						return vtab
					end,
					name = "最低品质",
					set = function(info, value) ZL.opt.minQuality = value end,
					get = function() return ZL.opt.minQuality end,
					order = 6,
					width = "full",
				},
				auctionTimer = {
					type = "range",
					softMin = 10,
					softMax = 3600,
                    step = 1,
					order = 7,
					name = "初始拍卖时间",
					desc = "因未收到出价而结束拍卖所必须等待的秒数",
					set = function(info, value) ZL.opt.auctionTimer = value end,
					get = function() return ZL.opt.auctionTimer end,
					disabled = function () return (not PlayerIsML()) end,
				},
				auctionTimerRefresh = {
					type = "range",
					softMin = 5,
					softMax = 3600,
                    step = 1,
					order = 8,
					name = "重置拍卖时间",
					desc = "收到最后出价后直到拍卖成功所需要等待的秒数",
					set = function(info, value)
						ZL.opt.auctionTimerRefresh = value
					end,
					get = function()
						ZL.TransmitAddonInfo_Pro()
						return ZL.opt.auctionTimerRefresh
					end,
				},
				countdownTimerJump = {
					type = "range",
					softMin = 60,
					softMax = 1800,
                    step = 1,
					order = 8.5,
					name = "自动提醒频率",
					desc = "每次剩余时间通告之间的秒数",
					set = function(info, value) ZL.opt.countdownTimerJump = value end,
					get = function() return ZL.opt.countdownTimerJump end,
					disabled = true,
				},
				manualCountdownTimer = {
					type = "range",
					softMin = 5,
					softMax = 30,
                    step = 1,
					order = 8.7,
					name = "手动倒数时间",
					desc = "手动倒计时后直到拍卖结束所需要等待的秒数",
					set = function(info, value) ZL.opt.manualCountdownTimer = value end,
					get = function() return ZL.opt.manualCountdownTimer end,
				},
				awardToML = {
					type = "toggle",
					name = "自动分配物品给分ML",
					set = function(info, value) ZL.opt.awardToML = value end,
					get = function() return ZL.opt.awardToML end,
					width = "full",
					order = 10,
					disabled = function() return not not ZL.opt.autoAwardLoot end,
				},
				allowMultiple = {
					type = "toggle",
					name = "允许同时拍卖多项物品",
					width = "full",
					set = function(info, value) ZL.opt.allowMultipleAuctions = value end,
					get = function() return ZL.opt.allowMultipleAuctions end,
					-- disabled = function() return ((ZL.curAuctions and (#ZL.curAuctions > 0)) or (ZL.curAuction.item)) end, --临时取消，做测试
					order = 13,
				},
				confirmLootAnnounce= {
					type = "toggle",
					name = "是否拾取通报",
					width = "full",
					set = function(info, value) ZL.opt.confirmLootAnnounce = value end,
					get = function() return ZL.opt.confirmLootAnnounce end,
					order = 16,
				},
				remindInvalidBid = {
					type = "toggle",
					name = "向出价过低的用户发送无效出价提醒",
					width = "full",
					set = function(info, value) ZL.opt.remindInvalidBid = value end,
					get = function() return ZL.opt.remindInvalidBid end,
					order = 20,
				},
			},
			order = 1,
			disabled = function () return (not PlayerIsML()) end,
		},
		appearance = {
			type = "group",
			name = "外观选项",
			args = {
				buttonReenableDelay = {
					type = "range",
					min = 0,
					max = 10,
					softMax = 1,
					softMin = 0,
					name = "出价按钮间隔时间",
					order = 6,
					set = function(info, value) ZL.opt.buttonReenableDelay = value end,
					get = function() return ZL.opt.buttonReenableDelay end,
				},
			},
			order = 2,
			disabled = true,
			hidden = true,
		},
		notification = {
			type = "group",
			name = "提示选项",
			args = {
				rules = {
					type = "input",
					name = "拍卖规则",
					order = 1,
					multiline = true,
					get = function() return ZL.opt.rulesString or "" end,
					set = function(info, value)
						ZL.opt.rulesString = string.len(value) > 0 and value
					end,
					width = "full",
				},
				welcomeMessage = {
					dialogInline = true,
					name = "加入团队时欢迎语(团长权限)",
					order = 2,
					type = "group",
					args = {
						isEnabled = {
							order = 1,
							type = "toggle",
							name = "启用",
							set = function(info, value) ZL.opt.welcomeMessageEnable = value end,
							get = function() 
								if ZL.opt.MessageString and string.len(ZL.opt.MessageString) > 0 then
									return ZL.opt.welcomeMessageEnable
								else
									ZL.opt.welcomeMessageEnable = false
									return ZL.opt.welcomeMessageEnable
								end
							end,
							width = "half",
							disabled = function ()
								if ZL.opt.MessageString and string.len(ZL.opt.MessageString) > 0 then
									return false
								else
									ZL.opt.welcomeMessageEnable = false
									return true
								end
							end,
						},
						Message = {
							type = "input",
							name = "欢迎语",
							order = 2,
							multiline = true,
							get = function() return ZL.opt.MessageString or "" end,
							set = function(info, value)
								if string.len(value) > 0 then
									ZL.opt.MessageString = value
								else
									ZL.opt.MessageString = ""
								end
							end,
							width = "full",
						},
					},
				},
			},
			order = 3,
		},
		visibility = {
			type = "group",
			name = "可见性设置",
			args = {
				hideCombatFrames = {
					type = "multiselect",
					name = "战斗中隐藏窗口",
					values = {
						status = "隐藏状态窗口与余额窗口",
						history = "隐藏历史记录窗口",
						vercheck = "隐藏版本检查窗口",
					},
					set = function(info, key, value)
						ZL.opt.hideCombat[key] = value
						if InCombatLockdown() then
							if key == "history" and value then
								ZL.AuctionRecordFrame:Hide()
							end
							if key == "vercheck" and value then
								-- ZL.version:Hide()
							end
						end
					end,
					get = function(info, key) return ZL.opt.hideCombat[key] end,
					order = 1,
					width = "full",
				},
			},
			order = 4,
			disabled = true,
			hidden = true,
		},
	},
}


